<template>
	<view>
		<uv-tabs
			:list="list"
			:scrollable="false"
			:current="current"
			@change="changeIndex"
			:activeStyle="{
				color: '#5c89ec',
				fontSize: '14px',
				fontWeight: 'bold',
				transform: 'scale(1.1)'
			}"
			:inactiveStyle="{
				color: '#606266',
				fontSize: '12px',
				transform: 'scale(1)'
			}"
		></uv-tabs>
		<block v-if="+value === 0">
			<view :class="qfbg" v-if="+deviceType === 46 || deviceType == '00'"><image :src="qfUrl" mode="aspectFit" style="margin-top:42rpx;height:188rpx;" :style="imageStyle"></image></view>
			<view :class="stfbg" v-if="+deviceType === 49"><image :src="qfUrl" mode="aspectFit" style="margin-top:250rpx;height:188rpx;" :style="imageStyle"></image></view>
			<uv-grid :border="true" :col="4">
				<uv-grid-item v-for="(item,index) in stateArr" :key="index" style="padding-bottom:24rpx;">
					<text class="grid-text">{{getValue(item)}}</text>
					<uv-icon :customStyle="{paddingTop:16+'rpx'}" :name="item.name" :size="10"></uv-icon>
				</uv-grid-item>
			</uv-grid>
			<view class="h12"></view>
			<uv-cell-group>
				<block
					v-for="(item, index) in actionArr.filter(val => {
						return !val.top && val.deviceType.includes(deviceType);
					})"
					:key="'second' + index"
				>
					<uv-cell :title="item.name" :isLink="true" arrow-direction="right" @click="showAction(item)"></uv-cell>
				</block>
				<uv-gap height="30" bgColor="#eaeaea"></uv-gap>
				<block
					v-for="(item, index) in actionArr.filter(val => {
						return val.top;
					})"
					:key="index"
				>
					<uv-cell :title="item.name" :isLink="true" arrow-direction="right" @click="showAction(item)"></uv-cell>
					<view style="margin:25rpx 25rpx 0 25rpx;"><uv-button type="primary" @click="readSetting(1, 1)">刷新</uv-button></view>
				</block>
			</uv-cell-group>
			<!-- <uv-cell-group>
				<block v-for="(item, index) in stateArr" :key="'first' + index">
					<uv-cell cellStyle="{font-size:24rpx;}" :icon="item.icon" :title="item.name" :value="getValue(item)"></uv-cell>
				</block>
				<view style="margin:25rpx 25rpx 0 25rpx;"><uv-button type="primary" @click="readSetting(1, 1)">刷新</uv-button></view>
			</uv-cell-group> -->
		</block>
		<!-- <block v-if="+value === 1">
			<uv-cell-group>
				<block
					v-for="(item, index) in actionArr.filter(val => {
						return !val.top && val.deviceType.includes(deviceType);
					})"
					:key="'second' + index"
				>
					<uv-cell :title="item.name" :isLink="true" arrow-direction="right" @click="showAction(item)"></uv-cell>
				</block>
				<uv-gap height="30" bgColor="#eaeaea"></uv-gap>
				<block
					v-for="(item, index) in actionArr.filter(val => {
						return val.top;
					})"
					:key="index"
				>
					<uv-cell :title="item.name" :isLink="true" arrow-direction="right" @click="showAction(item)"></uv-cell>
				</block>
			</uv-cell-group>
		</block> -->
		<block v-if="+value === 2">
			<uv-cell-group>
				<block v-for="(item, index) in settingArr" :key="'third' + index">
					<uv-cell
						v-if="item.type === 'select'"
						:value="getSettingValue(settingObj, item)"
						:title="item.name"
						cellStyle="{font-size:28rpx;}"
						:isLink="true"
						@click="showSetting(item)"
					/>
					<uv-cell v-else :title="item.name" cellStyle="{font-size:28rpx;}">
						<template v-slot:value>
							<uv-button v-if="item.type === 'button'" @click="sendCommand(item)" type="primary" size="small" text="确定"></uv-button>
							<uv-switch v-if="item.type === 'switch'" :inactiveValue="0" :activeValue="1" v-model="item.value" @change="sendCommand(item)"></uv-switch>
						</template>
					</uv-cell>
				</block>
			</uv-cell-group>
			<view style="margin:25rpx;"><uv-button type="primary" @click="readSetting(2, 1)">刷新</uv-button></view>
		</block>
		<block v-if="+value === 3">
			<uv-cell-group>
				<block v-for="(item, index) in settingAllArr" :key="'fourth' + index">
					<uv-cell
						v-if="['select', 'input', 'slider'].includes(item.type)"
						:value="getSettingValue(settingAllObj, item)"
						:title="item.name"
						cellStyle="{font-size:28rpx;}"
						:isLink="true"
						@click="showSetting(item)"
					/>
					<uv-cell v-else :value="getSettingValue(settingAllObj, item)" :title="item.name" cellStyle="{font-size:28rpx;}">
						<template v-slot:value>
							<block v-if="item.type === 'button'">
								<text style="font-size:28rpx;margin-right:8rpx;">{{ getSettingValue(settingAllObj, item) }}</text>
								<uv-button @click="sendCommand(item)" type="primary" size="small" text="确定"></uv-button>
							</block>
							<block v-if="['readonly'].includes(item.type)">
								<text style="font-size:28rpx;margin-right:8rpx;">{{ getSettingValue(settingAllObj, item) }}</text>
							</block>
							<uv-switch v-if="item.type === 'switch'" :inactiveValue="0" :activeValue="1" v-model="item.value" @change="sendCommand(item)"></uv-switch>
						</template>
					</uv-cell>
				</block>
			</uv-cell-group>
			<view style="margin:25rpx;"><uv-button type="primary" @click="readSetting(3, 1)">刷新</uv-button></view>
		</block>

		<block v-if="+value === 4">
			<uv-cell-group>
				<block v-for="(item, index) in settingFmArr" :key="'third' + index">
					<uv-cell
						v-if="item.type === 'select'"
						:value="getSettingValue(settingFmObj, item)"
						:title="item.name"
						cellStyle="{font-size:28rpx;}"
						:isLink="true"
						@click="showSetting(item)"
					/>
					<uv-cell v-else :value="getSettingValue(settingFmObj, item)" :title="item.name" cellStyle="{font-size:28rpx;}">
						<template v-slot:value>
							<block v-if="item.type === 'button'">
								<text style="font-size:28rpx;margin-right:8rpx;">{{ getSettingValue(settingFmObj, item) }}</text>
								<uv-button @click="sendCommand(item)" type="primary" size="small" text="确定"></uv-button>
							</block>
							<uv-switch v-if="item.type === 'switch'" :inactiveValue="0" :activeValue="1" v-model="item.value" @change="sendCommand(item)"></uv-switch>
						</template>
					</uv-cell>
				</block>
			</uv-cell-group>
			<view style="margin:25rpx;"><uv-button type="primary" @click="readSetting(4, 1)">刷新</uv-button></view>
		</block>

		<block v-if="+value === 5">
			<uv-cell-group>
				<block v-for="(item, index) in setting4GArr" :key="'fifth' + index">
					<uv-cell
						v-if="['select', 'input', 'slider'].includes(item.type)"
						:value="getSettingValue(setting4GObj, item)"
						:title="item.name"
						cellStyle="{font-size:28rpx;}"
						:isLink="true"
						@click="showSetting(item)"
					/>
					<uv-cell v-else :value="getSettingValue(setting4GObj, item)" :title="item.name" cellStyle="{font-size:28rpx;}">
						<template v-slot:value>
							<block v-if="['readonly'].includes(item.type)">
								<text style="font-size:28rpx;margin-right:8rpx;">{{ getSettingValue(setting4GObj, item) }}</text>
							</block>
							<uv-switch v-if="item.type === 'switch'" :inactiveValue="0" :activeValue="1" v-model="item.value" @change="sendCommand(item)"></uv-switch>
						</template>
					</uv-cell>
				</block>
			</uv-cell-group>
			<view style="display:flex;margin:25rpx;">
				<uv-button type="primary" style="flex:1;margin-right:25rpx;" @click="readSetting(5, 1)">刷新</uv-button>
				<uv-button type="success" style="flex:1;margin-right:25rpx;" @click="initial()">配置</uv-button>
				<uv-button type="warning" style="flex:1;margin-right:25rpx;" @click="restart()">重启</uv-button>
				<uv-button type="error" style="flex:1" @click="clear()">清空</uv-button>
			</view>
		</block>

		<block v-if="+value === 6">
			<view :class="fkqClass">
				<!-- <image :src="fkqUrl" mode="widthFix"></image> -->
			</view>
			<uv-cell-group>
				<block v-for="(item, index) in settingFkqArr" :key="'fifth' + index">
					<uv-cell
						v-if="['select', 'input', 'slider'].includes(item.type)"
						:value="getSettingValue(settingFkqObj, item)"
						:title="item.name"
						cellStyle="{font-size:28rpx;}"
						:isLink="true"
						@click="showSetting(item)"
					/>
					<uv-cell v-else :value="getSettingValue(settingFkqObj, item)" :title="item.name" cellStyle="{font-size:28rpx;}">
						<template v-slot:value>
							<block v-if="['readonly'].includes(item.type)">
								<text style="font-size:28rpx;margin-right:8rpx;">{{ getSettingValue(settingFkqObj, item) }}</text>
							</block>
							<uv-switch v-if="item.type === 'switch'" :inactiveValue="0" :activeValue="1" v-model="item.value" @change="sendCommand(item)"></uv-switch>
						</template>
					</uv-cell>
				</block>
			</uv-cell-group>
			<view style="margin:25rpx;"><uv-button type="primary" @click="readSetting(6, 1)">刷新</uv-button></view>
		</block>
		
		<block v-if="+value === 7">
			<uv-cell-group>
				<block v-for="(item, index) in settingDdfArr" :key="'fifth' + index">
					<uv-cell
						v-if="['select', 'input', 'slider'].includes(item.type)"
						:value="getSettingValue(settingDdfObj, item)"
						:title="item.name"
						cellStyle="{font-size:28rpx;}"
						:isLink="true"
						@click="showSetting(item)"
					/>
					<uv-cell v-else :value="getSettingValue(settingDdfObj, item)" :title="item.name" cellStyle="{font-size:28rpx;}">
						<template v-slot:value>
							<block v-if="['readonly'].includes(item.type)">
								<text style="font-size:28rpx;margin-right:8rpx;">{{ getSettingValue(settingDdfObj, item) }}</text>
							</block>
							<uv-switch v-if="item.type === 'switch'" :inactiveValue="0" :activeValue="1" v-model="item.value" @change="sendCommand(item)"></uv-switch>
						</template>
					</uv-cell>
				</block>
			</uv-cell-group>
			<view style="margin:25rpx;"><uv-button type="primary" @click="readSetting(7, 1)">刷新</uv-button></view>
		</block>
		<uv-popup ref="popup" mode="bottom">
			<view class="title">
				<text>{{ actionItem.name }}</text>
			</view>
			<view style="padding:12rpx 0;">
				<block v-if="actionItem.type === 'slider'"><uv-slider show-value v-model="actionItem.value"></uv-slider></block>
				<block v-if="actionItem.type === 'input'">
					<view style="padding:0 25rpx;">
						<uv-input type="text" :placeholder="getPlaceHolder(actionItem)" v-model="actionItem.value" border="surround" clearable>
							<template v-slot:suffix>
								{{ actionItem.suffix || '' }}
							</template>
						</uv-input>
					</view>
				</block>
			</view>
			<uv-button type="primary" style="margin:25rpx;" @click="sendCommand(actionItem)">确定</uv-button>
		</uv-popup>
		<uv-picker ref="picker" :defaultIndex="getIndex(actionItem)" :columns="getColumns(actionItem)" @confirm="confirm"></uv-picker>
	</view>
</template>

<script>
import { toast, modal, loading, convertArr2Obj } from '@/util';
import { stateArr, actionArr, settingArr, settingFmArr, settingAllArr, setting4GArr, settingFkqArr,settingDdfArr } from '@/util/constant';
import { states, setting, settingFm, settingAll, command, commandRaw, commandForChar } from '@/util/formatter';
import { mapGetters } from 'vuex';
import { setField } from '@/api/device'
export default {
	props: {
		notifyData: {
			type: String,
			default() {
				return '';
			}
		},
		settingData: {
			type: String,
			default() {
				return '';
			}
		},
		settingFmData: {
			type: String,
			default() {
				return '';
			}
		},
		settingAllData: {
			type: String,
			default() {
				return '';
			}
		},
		setting4GData: {
			type: String,
			default() {
				return '';
			}
		},
		settingFkqData: {
			type: String,
			default() {
				return '';
			}
		},
		settingDdfData: {
			type: String,
			default() {
				return '';
			}
		}
	},
	data() {
		return {
			current: 0,
			value:3,
			actionItem: {},
			actionArr,
			settingArr,
			settingFmArr,
			settingAllArr,
			stateArr,
			setting4GArr,
			settingFkqArr,
			settingDdfArr,
			settingObj: {},
			settingFmObj: {},
			settingAllObj: {},
			setting4GObj:{},
			settingFkqObj:{},
			settingDdfObj:{},
			fkqUrl:require('../static/device/fkq/00.png'),
			qfUrl:require('../static/device/qf/qf.png'),
			qfbg:'qfbg',
			stfbg:'stf',
			imageStyle:'',
			fkqClass:'',
			deviceType:'',
			deviceCode:'',
			list:[{
					value: 3,
					name: '通用设置',
					superable: 0
				}]
		};
	},
	computed: {
		...mapGetters(['user','mqttHost', 'mqttPort', 'mqttUser', 'mqttPassword']),
	},
	watch: {
		value:{
			handler(newVal){
				if(newVal > 0){
					console.log('stopFetchData')
					this.$emit('stopFetchData')
				} else {
					console.log('fetchData')
					this.$emit('fetchData')
				}
			},
			deep:true,
			immediate:true
		},
		user: {
			handler(newVal) {
				if (+newVal.superable === 0) {
					this.actionArr = this.actionArr.filter(val => {
						return +val.superable === 0;
					});
					this.settingArr = this.settingArr.filter(val => {
						return +val.superable === 0;
					});
					this.settingFmArr = this.settingFmArr.filter(val => {
						return +val.superable === 0;
					});
					this.settingAllArr = this.settingAllArr.filter(val => {
						return +val.superable === 0;
					});
					this.setting4GArr = this.setting4GArr.filter(val => {
						return +val.superable === 0;
					});
					this.settingFkqArr = this.settingFkqArr.filter(val => {
						return +val.superable === 0;
					});
					this.settingDdfArr = this.settingDdfArr.filter(val => {
						return +val.superable === 0;
					});
				}
			},
			immediate: true,
			deep: true
		},
		notifyData: {
			handler(newVal) {
				this.stateArr = states(newVal, 613);
				this.getImageStyle(this.stateArr)
				this.getQfbg(this.stateArr)
			},
			immediate: true
		},
		settingData: {
			handler(newVal) {
				if (newVal) {
					const settingResult = setting(newVal, 3, 300);
					this.settingObj = convertArr2Obj(settingResult, 'addr');
				}
			},
			immediate: true
		},
		settingFmData: {
			handler(newVal) {
				if (newVal) {
					const settingFmResult = setting(newVal, 2, 600);
					this.settingFmObj = convertArr2Obj(settingFmResult, 'addr');
				}
			},
			immediate: true
		},
		settingAllData: {
			handler(newVal) {
				const settingAllResult = setting(newVal, 4, 0);
				this.settingAllObj = convertArr2Obj(settingAllResult, 'addr');
				const deviceValue = newVal.substr(8,4)
				this.deviceCode = deviceValue.substr(2,2)
				this.deviceType = deviceValue.substr(0,2)
				this.list = this.list.concat(this.getList())
			},
			immediate: true
		},
		setting4GData: {
			handler(newVal) {
				console.log(newVal)
				const setting4GResult = setting(newVal, 5, 350);
				this.setting4GObj = convertArr2Obj(setting4GResult, 'addr');
			},
			immediate: true
		},
		settingFkqData: {
			handler(newVal) {
				const settingFkqResult = setting(newVal, 6, 800);
				this.settingFkqObj = convertArr2Obj(settingFkqResult, 'addr');
				const DO1 = this.settingFkqObj[808].value || 0
				const DO2 = this.settingFkqObj[809].value || 0
				this.fkqClass = `fkq${DO1}${DO2}`
			},
			immediate: true
		},
		settingDdfData: {
			handler(newVal) {
				const settingDdfResult = setting(newVal, 7, 800);
				this.settingDdfObj = convertArr2Obj(settingDdfResult, 'addr');
			},
			immediate: true
		}
	},
	methods: {
		getList() {
			let arr = [
				{
					value: 0,
					name: '球阀',
					superable: 0,
					deviceType:['46','49','00'],
				},
				// {
				// 	value: 1,
				// 	name: '球阀控制',
				// 	superable: 0,
				// 	deviceType:['46','45'],
				// },
				{
					value: 2,
					name: '射频设置',
					superable: 0,
					deviceCode:'00'
				},
				{
					value: 4,
					name: '阀门设置',
					superable: 1,
					deviceType:['46','49','00']
				},
				{
					value: 5,
					name: '4G设置',
					superable: 0,
					deviceCode:'01'
				},
				{
					value: 6,
					name: '脉冲阀控',
					superable: 0,
					deviceType:['47']
				},
				{
					value: 7,
					name: '电动阀',
					superable: 0,
					deviceType:['48']
				}
			];
			arr = arr.filter((val) => {
				if(val.deviceType){
					return val.deviceType.includes(this.deviceType)
				}
				if(val.deviceCode){
					return val.deviceCode === this.deviceCode
				}
				return val
			})
			const res = arr.filter(val => {
				if (!this.user.superable) {
					return +val.superable === 0;
				} else {
					return val;
				}
			});
			return res
		},
		getImageStyle(states) {
			const A = states[0]['value'] || 9000;
			const degree = Math.round(A / 100);
			let marginTop = '42rpx'
			this.imageStyle = {
				height:'188rpx',
				transform: `rotate(${degree - 90}deg)`,
				transition: 'transform 0.5s ease' // 可选的过渡效果
			};
		},
		getQfbg(states) {
			const A = states[0]['value'] || 9000;
			const degree = Math.round(A / 100);
			this.qfbg = 'qfbg1';
			if (degree >= 89 && degree <= 90) {
				this.qfbg = 'qfbg';
			}
			if (degree > 90 && degree <= 270) {
				this.qfbg = 'qfbg2';
			}
		},
		clear(){
			modal(
				'操作确认',
				`确定要清空配置参数吗？`,
				() => {
				const initDatas = [
					{addr:374,code:'06',value:0,time:900},
					{addr:375,code:'10',value:'',time:900},
					{addr:395,code:'10',value:'',time:900},
					{addr:415,code:'10',value:'',time:900},
					{addr:435,code:'10',value:'',time:900},
					{addr:455,code:'10',value:'',time:900},
					{addr:475,code:'10',value:'',time:900},
				]
				this.multiWrite(initDatas)
			})
		},
		initial(){
			console.log(this.mqttUser)
			const ICCID = this.setting4GObj['351'].value
			const IMEI = this.setting4GObj['362'].value
			const initDatas = [
				{addr:374,code:'06',value:this.mqttPort,time:900},
				{addr:375,code:'10',value:this.mqttHost,time:900},
				{addr:395,code:'10',value:ICCID,time:900},
				{addr:415,code:'10',value:this.mqttUser,time:900},
				{addr:435,code:'10',value:this.mqttPassword,time:900},
				{addr:455,code:'10',value:`B/${IMEI}`,time:900},
				{addr:475,code:'10',value:`B/${IMEI}/DW`,time:900},
			]

			this.multiWrite(initDatas)
		},
		multiWrite(initDatas){
			loading('设置中')
			initDatas.forEach((item,index) => {
				let value = ''
				if(item.code === '06'){
					value = command(item.addr,item.value,item.code)
				} else {
					value = commandForChar(item.addr,item.value,item.code)
				}
				setTimeout(() => {
					this.$emit('sendCommand',value,'multi')
				},1000*(index+1))
			})
			setTimeout(() => {
				toast('操作成功');
				uni.hideLoading()
				this.readSetting(5, 1)
			},1000*initDatas.length)
		},
		restart(){
			this.$emit('sendCommand',command(15,1,'06'),'single',12000,'重启中',() => {
				this.$emit('sendCommand',command(21,1,'06'),'single',2000)
			})
		},
		resetStates() {
			this.actionItem = {};
		},
		getSettingValue(obj, attr) {
			const item = obj[attr.addr] || {};
			if (item.value !== undefined && item.value !== '') {
				let value = item.value;
				if(item.type === 'readonly' && item.enums.length > 0){
					const enumsObj = convertArr2Obj(item.enums,'value')
					console.log(item.value)
					if(item.value!==undefined && item.value !==''){
						return enumsObj && enumsObj[+item.value] && enumsObj[+item.value].name
					}
					return ''
				}else{
					if (item.kunit) {
						value = value * item.kunit;
					}
					if (item.toFixed > 0) {
						value = value.toFixed(item.toFixed);
					}
					if (item.valueText) {
						return item.valueText;
					}
					return value.toString() + (item.unit || '');
				}
			}
			return '';
		},
		readSetting(idx, showCommand = 0) {
			this.$emit('readSetting', idx, showCommand);
		},
		getPlaceHolder(item) {
			let extra = '';
			if (item.enums[0].params) {
				extra = '(' + item.enums[0].params[0] + '到' + item.enums[0].params[1] + '之间)';
			}
			return item.name + extra;
		},
		changeIndex(val) {
			this.value = val.value;
			this.current = this.list.findIndex((item) => {
				return item.value === this.value
			})
			if (val.index >= 2) {
				this.readSetting(val.index);
			}
		},
		showSetting(item) {
			this.actionItem = item;
			if (item.type === 'select') {
				this.$refs.picker.open();
			}
			if (['slider', 'input'].includes(item.type)) {
				this.open();
			}
		},
		getColumns(item) {
			if (item && item.enums) {
				return [item.enums.map(val => val.name)];
			}
			return [];
		},
		getIndex(item) {
			let obj = this.settingObj;
			if (this.value === 2) {
				obj = this.settingFmObj;
			}
			if (this.value === 4) {
				obj = this.settingAllObj;
			}
			if (this.value === 5) {
				obj = this.setting4GObj;
			}
			if (this.value === 6) {
				obj = this.settingFkqObj;
			}
			if (this.value === 7) {
				obj = this.settingDdfObj;
			}
			if (item && item.enums) {
				if (obj && obj[item.addr] && obj[item.addr]['value']) {
					const res = item.enums.findIndex(val => {
						return +val.params === +obj[item.addr]['value'];
					});
					return [res];
				}
			}
			return [0];
		},
		confirm(e) {
			const index = e.indexs[0];
			const item = this.actionItem.enums[index];
			item.value = item.params;
			this.sendCommand(item, `确定要将${this.actionItem.name}设置为${item.name}吗?`);
		},
		getValue(item) {
			if (item.value !== undefined && item.value !== '--') {
				let value = item.value * (item.kunit || 1);
				if (item.toFixed > 0) {
					value = value.toFixed(item.toFixed);
				}
				return value + (item.unit || '');
			}
			return '--';
		},
		showAction(item) {
			this.actionItem = item;
			if (['slider', 'input'].includes(item.type)) {
				this.open();
			}
			if (item.type === 'button') {
				this.sendCommand(item);
			}
			if (item.type === 'select') {
				uni.showActionSheet({
					itemList: item.enums.map(val => val.name),
					success: res => {
						const citem = this.actionItem.enums[res.tapIndex];
						citem.value = citem.params;
						this.sendCommand(citem, `确定要将进行此操作吗?`);
					}
				});
			}
		},
		open() {
			this.$refs.popup.open();
		},
		sendCommand(item, title) {
			if (item.type === 'input' && item.enums[0].params) {
				if (item.value < item.enums[0].params[0] || item.value > item.enums[0].params[1]) {
					toast('您设置的值超出可设定范围');
					return;
				}
			}
			modal(
				'操作确认',
				title || `确定要进行 ${item.name} 操作吗？`,
				() => {
					if (item.type === 'button' && item.name === '实时位置设置') {
						uni.getLocation({
							type: 'wgs84',
							success: res => {
								const { latitude, longitude } = res;
								const latHex = (latitude * 1000000).toString(16).padStart(8, 0);
								const lngHex = (longitude * 1000000).toString(16).padStart(8, 0);
								const values = [lngHex.substr(0, 4), lngHex.substr(4, 4), latHex.substr(0, 4), latHex.substr(4, 4)];
								
								let lng = values[0] + values[1]
								let lat = values[2] + values[3]
								
								// 将经纬度信息同步至远程数据库
								this.readSetting(5)
								setTimeout(() => {
									let lng = values[0] + values[1]
									let lat = values[2] + values[3]
									lng = parseInt(`0x${lng}`)/1000000 
									lat = parseInt(`0x${lat}`)/1000000
									const IMEI = this.setting4GObj[362].value || ''
									if(IMEI){
										setField(IMEI,{lat,lng}).then((rs) => {
											console.log(rs)
										}).catch((err) => {
											console.log(err)
										})
									}
								},2000)
								
								item.enums.reduce((promise, item, index) => {
									return promise.then(() => {
										return new Promise(resolve =>
											setTimeout(() => {
												const value = commandRaw(item.addr, values[index]);
												this.$emit('sendCommand', value);
								  		resolve();
											}, 500)
										);
									});
								}, Promise.resolve());
							},
							fail: err => {
								toast('请先打开手机定位再进行定位');
							}
						});
					} else {
						let itemValue = item.value
						if(['3#开度','4#开度'].includes(item.name)){
							itemValue = item.value + 110
						}
						
						let value = command(item.addr, itemValue, '06', item.len);
						if (item.dataType === 'char') {
							try{
								value = commandForChar(item.addr, itemValue, '10');
							}catch(e){
								toast(e.message)
								return
							}
						}
						console.log(value)
						this.$emit('sendCommand', value);
					}
				},
				() => {
					toast('cancel');
				}
			);
		}
	}
};
</script>

<style lang="scss">
.grid-text {
	font-size: 14px;
	color: #5c89ec;
	padding: 24rpx 0 0rpx 0rpx;
	font-weight: bold;
	/* #ifndef APP-PLUS */
	box-sizing: border-box;
	/* #endif */
}	
.title {
	text-align: center;
	height: 96rpx;
	line-height: 96rpx;
	text {
		font-weight: bold;
		border-bottom: 4rpx solid #3c9cff;
		padding-bottom: 12rpx;
	}
}
.fkq00 {
	background: url(../static/device/fkq/00.png) no-repeat center center;
	background-size: 100%;
	width: 640rpx;
	height:463rpx;
	margin: 5% 5% 0 5%;
}
.fkq01 {
	background: url(../static/device/fkq/01.png) no-repeat center center;
	background-size: 100%;
	width: 640rpx;
	height:463rpx;
	margin: 5% 5% 0 5%;
}
.fkq10 {
	background: url(../static/device/fkq/10.png) no-repeat center center;
	background-size: 100%;
	width: 640rpx;
	height:463rpx;
	margin: 5% 5% 0 5%;
}
.fkq11 {
	background: url(../static/device/fkq/11.png) no-repeat center center;
	background-size: 100%;
	width: 640rpx;
	height:463rpx;
	margin: 5% 5% 0 5%;
}
.qfbg {
	background: url(../static/device/qf/qfbg.png) no-repeat;
	background-size: 100%;
	height: 300rpx;
	margin: 5% 5% 0 5%;
}
.qfbg1 {
	background: url(../static/device/qf/qfbg1.png) no-repeat;
	background-size: 100%;
	height: 300rpx;
	margin: 5% 5% 0 5%;
}
.qfbg2 {
	background: url(../static/device/qf/qfbg2.png) no-repeat;
	background-size: 100%;
	height: 300rpx;
	margin: 5% 5% 0 5%;
}
.stf {
	background: url(../static/device/qf/stf.png) no-repeat;
	background-size: 100%;
	height: 680rpx;
	margin: 5%;
}
.stf1 {
	background: url(../static/device/qf/stf1.png) no-repeat;
	background-size: 100%;
	height: 680rpx;
	margin: 5%;
}
.stf2 {
	background: url(../static/device/qf/stf2.png) no-repeat;
	background-size: 100%;
	height: 680rpx;
	margin: 5%;
}
.stf3 {
	background: url(../static/device/qf/stf3.png) no-repeat;
	background-size: 100%;
	height: 680rpx;
	margin: 5%;
}
.stf4 {
	background: url(../static/device/qf/stf4.png) no-repeat;
	background-size: 100%;
	height: 680rpx;
	margin: 5%;
}
</style>
